#pragma once

#include<BWAPI.h>
#include<set>

#include"ControlerBase.h"
#include"Controlers.h"

using namespace BWAPI;
using namespace std;

class ZerglingControler : public ControlerBase
{
public:
	ZerglingControler(Unit* zergling)
		:ControlerBase(zergling)
	{
	}
	virtual void OnFrame()
	{
		if(IsDead())
		{
			return;
		}

		Position position = _unitToControl->getPosition();
		Broodwar->drawTextMap(position.x() , position.y() , "\x07 zergling");

		if(_state == UnKnown)
		{
			int minHp(9999);
			Unit* bestTarget(NULL);
			for each(Unit* whichTarget in _unitToControl->getUnitsInRadius(400))
			{
				if(Broodwar->self()->isEnemy(whichTarget->getPlayer()))
				{
					int hp = whichTarget->getHitPoints() + whichTarget->getShields();
					if(hp < minHp)
					{
						minHp = hp;
						bestTarget = whichTarget;
					}
				}
			}
			if(bestTarget != NULL)
			{
				Attack(bestTarget);
			}
		}

		ControlerBase::OnFrame();
	}
private:
};